package com.wind.taobao.api.trade.trade.convert
{
	import com.wind.taobao.api.trade.trade.model.TradeConfirmFee;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 *  TradeConfirmFee转换器
	 * @author fxy
	 *
	 */
	public class TradeConfirmFeeConvert
	{

		/**
		 * 转换TradeConfirmFee集合
		 */
		public static function convertTradeConfirmFees(value:Object, type:String="json"):ArrayCollection
		{
			var tradeConfirmFees:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							tradeConfirmFees.addItem(convertTradeConfirmFee((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return tradeConfirmFees;
		}

		/**
		 * 转换单个TradeConfirmFee对象
		 * value:XML 或 JSON
		 */
		public static function convertTradeConfirmFee(value:Object, type:String="json", tradeConfirmFee:TradeConfirmFee=null):TradeConfirmFee
		{
			if (tradeConfirmFee == null)
				tradeConfirmFee=new TradeConfirmFee();
			if (value == null)
				return tradeConfirmFee;
			if (type == TaobaoConstants.XML)
			{
				tradeConfirmFee=convertXMLToTradeConfirmFee(XML(value), tradeConfirmFee);
			}
			else
			{
				tradeConfirmFee=convertJSONToTradeConfirmFee(value, tradeConfirmFee);
			}
			return tradeConfirmFee;
		}

		/**
		 * JSON转换为TradeConfirmFee
		 */
		private static function convertJSONToTradeConfirmFee(json:Object, tradeConfirmFee:TradeConfirmFee):TradeConfirmFee
		{
			if (json.hasOwnProperty(TaobaoConstants.CONFIRM_FEE))
			{
				tradeConfirmFee.confirm_fee=json[TaobaoConstants.CONFIRM_FEE];
			}
			if (json.hasOwnProperty(TaobaoConstants.IS_LAST_DETAIL_ORDER))
			{
				tradeConfirmFee.is_last_detail_order=json[TaobaoConstants.IS_LAST_DETAIL_ORDER];//已转换Boolean
			}
			if (json.hasOwnProperty(TaobaoConstants.CONFIRM_POST_FEE))
			{
				tradeConfirmFee.confirm_post_fee=json[TaobaoConstants.CONFIRM_POST_FEE];
			}
			return tradeConfirmFee;
		}



		/**
		 * XML转换为TradeConfirmFee
		 */
		private static function convertXMLToTradeConfirmFee(value:XML, tradeConfirmFee:TradeConfirmFee):TradeConfirmFee
		{
			return tradeConfirmFee;
		}
	}
}